package com.wframe.project.former.dataservices.marketing;

import com.frame.database.JBaseService;
import com.frame.database.JServiceFactory;
import com.frame.database.JdataBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/6.
 */
public class PromotionsService extends JBaseService<PromotionsDao> {
    public static PromotionsService getIntance(){
        return JServiceFactory.createJServiceProxy(PromotionsService.class);
    }
    public  String addPromotions(JdataBean bean) throws Exception{
        String promotionsid =getDao().addPromotions(bean);
        return promotionsid;
    }
    public void updataStop(int id,int state) throws Exception{
        getDao().updateStop(id,state);
    }

    public JdataBean saveSession(int id) throws Exception{
        return getDao().saveSession(id);
    }
    public List<JdataBean> promotionControlsale(int id) throws Exception{
        return getDao().controlsalesPro(id);
    }

    public String productSingle (String proid) throws Exception{
        JdataBean jdataBean = getDao().productSingle(proid);
        String promotionId = null;
        if (jdataBean == null){
            promotionId = null;
        }else {
            promotionId = jdataBean.getString("id");
        }
        return promotionId;
    }

    public List<JdataBean> proSelect() throws Exception{
        return getDao().productSelect();
    }
    public String getProducrPrice (String productid) throws Exception {
        return getDao().getProducrPrice(productid);
    }
    public String getProductType (String productid) throws Exception {
        return getDao().getProductType(productid);
    }
    public String getProductMoneyOffTypeById (String productid) throws Exception {
        return getDao().getProductMoneyOffTypeById(productid);
    }


    public List<JdataBean> getSingleProductList (String promotionid) throws Exception{
        List<JdataBean> list = getDao().queryProductPromotionid(promotionid);
        List<JdataBean> product_list = new ArrayList<>();
        for (JdataBean jdataBean: list) {
            JdataBean jdataBean1= getDao().getSingleProduct((String.valueOf(jdataBean.get("productid"))));
            if(jdataBean1 !=null ) {
                product_list.add(jdataBean1);
            }

        }
        return product_list;
    }

    public JdataBean getSingleProduct(String productid) throws Exception {
      return getDao().getSingleProduct(productid);
        }

    public List<JdataBean> getProductPromotionTypeByIds(String[] productids) throws Exception {
        return getDao().getProductPromotionTypeByIds(productids);
    }
}
